﻿<div class="site-block">
    <div class="header">
        @ViewBag.ActiveUrl.Title
    </div>
   @* <table>
        <tr>
            <td>
                @ForumContext.AvatarRender(ForumContext.UserInfo.Avatar, ForumContext.UserInfo.Sex)
            </td>
            <td>
                <div id="fileuploadcontainer">
                    <div id="filelist"></div>
                    <a href="javascript://" id="pickfiles" class="ui-button">Browser...</a>
                </div>
            </td>
        </tr>
    </table>*@
     <div class="site-block-content">
        
        <fieldset>
            <legend>
                @ForumContext.GetMvcText(LanguageSection.AVATAR, "CURRENT_AVATAR")
            </legend>
            @ForumContext.AvatarRender(ForumContext.UserInfo.Avatar, ForumContext.UserInfo.Sex)
        </fieldset>
        <fieldset>
            <legend>
                @ForumContext.GetMvcText(LanguageSection.AVATAR, "UPDATE_AVATAR")
            </legend>
           
             <div id="fileuploadcontainer">
                    <div id="filelist"></div>
                    <a href="javascript://" id="pickfiles" class="ui-button">Browser...</a>
                </div>
        </fieldset>
    </div>
</div>

@using (Html.BeginScriptBlock())
{
    
    <script type="text/javascript" src="/scripts/upload/plupload.full.js"></script>
    
    <script type="text/javascript">
        $(function () {
            var uploader = new plupload.Uploader({
                runtimes: 'gears,html5,flash,silverlight',
                browse_button: 'pickfiles',
                container: 'fileuploadcontainer',
                max_file_size: '1mb',
                url: '@ViewBag.ActiveUrl.Url',
                flash_swf_url: '/scripts/upload/plupload.flash.swf',
                silverlight_xap_url: '/scripts/upload/plupload.silverlight.xap',
                filters: [{ title: "Image files", extensions: "jpg,gif,png,jpeg"}],
                resize: { width: 320, height: 240, quality: 90 }
            });

            /*  uploader.bind('Init', function (up, params) {
            $('#filelist').html("<div>Current runtime: " + params.runtime + "</div>");
            });*/

            /*  $('#uploadfiles').click(function (e) {
            uploader.start();
            e.preventDefault();
            });
            */
            uploader.init();

            uploader.bind('FilesAdded', function (up, files) {
                $.each(files, function (i, file) {
                    $('#filelist').append(
				'<div id="' + file.id + '">' +
				file.name + ' (' + plupload.formatSize(file.size) + ') <b></b>' +
			'</div>');


                });

                $.Loading.show();

                up.refresh(); // Reposition Flash/Silverlight

                uploader.start();
            });

            uploader.bind('UploadProgress', function (up, file) {
                $('#' + file.id + " b").html(file.percent + "%");
            });

            uploader.bind('Error', function (up, err) {
                $('#filelist').append("<div>Error: " + err.code +
			", Message: " + err.message +
			(err.file ? ", File: " + err.file.name : "") +
			"</div>"
		);

                up.refresh(); // Reposition Flash/Silverlight
            });

            uploader.bind('FileUploaded', function (up, file) {
                $.MvcForum.jump(window.location.href);
            });
        });
    </script>
}
